package cn.tedu.spotms.server.controller;

import cn.tedu.spotms.server.pojo.dto.SightDTO;
import cn.tedu.spotms.server.pojo.vo.SightSimpleVO;
import cn.tedu.spotms.server.service.ISightService;
import cn.tedu.spotms.server.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "景点管理模块")
@RequestMapping(value = "/sight",produces = "application/json;charset=utf-8")
public class SightController {

    @Autowired
    ISightService sightService;

    @PostMapping("/add-new")
    @ApiOperation("添加景点")
    @PreAuthorize("hasAuthority('/sight/update')")
    public JsonResult<Void> addNewSight(SightDTO sightDTO){
        sightService.addNewSight(sightDTO);
        return JsonResult.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除景点")
    @PreAuthorize("hasAuthority('/sight/delete')")
    public JsonResult<Void> deleteSightById(Integer id){
        sightService.deleteSightById(id);
        return JsonResult.ok();
    }


    @PostMapping("/update-info")
    @ApiOperation("修改景点信息")
    @PreAuthorize("hasAuthority('/sight/update')")
    public JsonResult<Void> updateInfoSight(SightDTO sightDTO){
        sightService.updateSightInfo(sightDTO);
        return JsonResult.ok();
    }
    @GetMapping("/listAll")
    @ApiOperation("所有景点列表展示")
    @PreAuthorize("hasAuthority('/sight/read')")
    public JsonResult<List<SightSimpleVO>> listAllSight(){
        List<SightSimpleVO> list = sightService.listAllInfo();
        return JsonResult.ok(list);
    }

}
